home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / gateway.idb / usr / OnRamp / lib / java.pm.z / java.pm
Encoding:
Text File  |  1997-07-30  |  11.4 KB  |  457 lines

  1. #!/usr/bin/perl5
  2.  
  3.  
  4. #------------------------------------------------------------
  5. $js_check_int =
  6. "function checkInt(check, base) {
  7.     if (base == 10) word = \"0123456789\";
  8.     else if (base == 16) word = \"0123456789abcdefABCDEF\";
  9.     else return (false);
  10.  
  11.     for (i=0; i<check.length; i++)
  12.         if (word.indexOf(check.charAt(i)) == -1) return (false);
  13.     return (true);
  14. }
  15. function checkInt_c(check, base) {
  16.     if (base == 10) word = \"0123456789\";
  17.     else if (base == 16) word = \"0123456789abcdefABCDEF\";
  18.     else return (false);
  19.  
  20.     if (word.indexOf(check) == -1) return (false);
  21.     return (true);
  22. }";
  23.  
  24.  
  25. #------------------------------------------------------------
  26. $js_account_main =
  27. "which = \"none\";
  28. function runSubmit() {
  29.     if(which == \"add\") return runAdd();
  30.     if(which == \"edit\") return runEdit();
  31.     if(which == \"delete\") return runDelete();
  32.     return (true);
  33. }
  34. function markAdd() { which = \"add\"; }
  35. function markEdit() { which = \"edit\"; }
  36. function markDelete() { which = \"delete\"; }
  37. function markOther() { which = \"none\"; }
  38. function runAdd()  {
  39.     form = document.AccountForm
  40.     if (!testAdd(form)) return (false);
  41.     return (true);
  42. }
  43. function runEdit()  {
  44.     Ctrl = document.AccountForm.chosen
  45.     none = true;
  46.     for(j = 0; j < Ctrl.length; j++) {
  47.         if (Ctrl.options[j].selected) { none = false; break; }
  48.     }
  49.     if (none) {
  50.         errorBox (Ctrl, \"To edit an existing \" + type + \", \"
  51.             + \"first select an \" + type + \"\\nfrom the list, \"
  52.             + \"then click the edit button.\");
  53.         return (false);
  54.     }    
  55.     return (true);
  56. }
  57. function runDelete() {
  58.     Ctrl = document.AccountForm.chosen;
  59.     none = true;
  60.     for(j = 0; j < Ctrl.length; j++) {
  61.         if (Ctrl.options[j].selected) { none = false; break; }
  62.     }
  63.     if (none) {
  64.         errorBox (Ctrl, \"To delete an existing \" + type + \", first \"
  65.             + \"select an \" + type + \"\\nfrom the list, then click \"
  66.             + \"the delete button.\");
  67.         return (false);
  68.     }
  69.     return (true);
  70. }";
  71.  
  72. #------------------------------------------------------------
  73. $js_account_add =
  74. "which = \"none\";
  75. function runSubmit() {
  76.     if(which == \"add\") return runAdd();
  77.     return (true);
  78. }
  79. function markAdd() { which = \"add\"; }
  80. function markOther() { which = \"none\"; }
  81. function runAdd()  {
  82.     form = document.AddForm;
  83.     if (!testAdd(form)) return (false);
  84.     return (true);
  85. }";
  86.  
  87.  
  88. #------------------------------------------------------------
  89. $js_account_edit =
  90. "which = \"none\";
  91. function runSubmit() {
  92.     if(which == \"edit\") return runEdit();
  93.     return (true);
  94. }
  95. function markEdit() { which = \"edit\"; }
  96. function markOther() { which = \"none\"; }
  97. function runEdit()  {
  98.     form = document.EditForm;
  99.     if (!testEdit(form)) return (false);
  100.     return (true);
  101. }";
  102.  
  103.  
  104. #------------------------------------------------------------
  105. $js_standard =
  106. "which = \"none\";
  107. function runSubmit() {
  108.     if(which == \"ok\") return runOK();
  109.     return (true);
  110. }
  111. function markOK() { which = \"ok\"; }
  112. function markOther() { which = \"none\"; }
  113. function runOK() {
  114.     form = document.StandardForm;
  115.     if (!checkForm(form)) return (false);
  116.     return (true);
  117. }";
  118.  
  119.  
  120. #------------------------------------------------------------
  121. $js_error_box =
  122. "function errorBox (Ctrl, ErrorMessage) {
  123.     alert (ErrorMessage);  Ctrl.focus();  return;
  124. }";
  125.  
  126.  
  127. #------------------------------------------------------------
  128. $js_phone =
  129. "$js_check_int
  130. function testPhone(Ctrl) {
  131.     if (Ctrl.value == \"\") {
  132.         errorBox (Ctrl, \"The phone number is required.\");
  133.         return (false);
  134.     }
  135.     error = testPhoneChars(Ctrl.value);
  136.     if (error == 1) {
  137.         errorBox (Ctrl, \"The phone number cannot contain spaces.\");
  138.         return (false);
  139.     }
  140.     if (error == 2) {
  141.         errorBox (Ctrl, \"The phone number cannot contain \"
  142.             + \"\\nletters or punctuation.\");
  143.         return (false);
  144.     }
  145.     return (true);
  146. }
  147. function testPhoneChars(word) {
  148.     for(i = 0; i < word.length; i++) {
  149.         c = word.charAt(i);
  150.         if (c == ' ') return 1;
  151.         if (c != \'(\' && c != \')\' && c != \'-\' && c != \',\') {
  152.             if (! checkInt_c(c, 10)) return 2;
  153. //            num = parseInt(c);
  154. //            if(isNaN(num)) return 2;
  155.         }
  156.     }
  157.     return 0;
  158. }";
  159.  
  160.  
  161. #------------------------------------------------------------
  162. $js_meta =
  163. "function testMeta(Ctrl, what) {
  164.     if (Ctrl.value == \"\") { 
  165.         errorBox (Ctrl, \"The \" + what + \" is required.\");
  166.         return (false);
  167.     }
  168.     error = testMetaChars(Ctrl.value);
  169.     if (error == 1) {
  170.         errorBox (Ctrl, \"The \" + what + \" cannot be more \"
  171.             + \"\\nthan 8 characters long.\");
  172.         return (false);
  173.     }
  174.     if (error == 2) {
  175.         errorBox (Ctrl, \"The \" + what + \" cannot contain \"
  176.             + \"the \" + illegal + \" character.\");
  177.         return (false);
  178.     }
  179.     if (error == 3) {
  180.         errorBox (Ctrl, \"The \" + what + \" cannot contain \"
  181.             + \"spaces.\");
  182.         return (false);
  183.     }
  184.     return (true);
  185. }
  186. function testMetaChars(word) {
  187.     if (word.length > 8) return 1;
  188.     loginChars = \"{}()*!~<>?|[]'&^\$\@\#`\\\";:\\\\/+=,%\";
  189.     for(j = 0; j < loginChars.length; j++) {
  190.         c = loginChars.charAt(j);
  191.         if (word.indexOf(c, 0) != -1) { illegal = c; return 2; }
  192.     }
  193.     for (c = 0; c < word.length; c++) {
  194.         if (word.charAt(c) == ' ') return 3;
  195.     }
  196.     return 0;
  197. }";
  198.  
  199.  
  200. #------------------------------------------------------------
  201. $js_iplist =
  202. "function testIPList(Ctrl, what) {
  203.     my_count = 0;
  204.     whitespace = \" \\n\\r\\t\\f\";  space = true;
  205.     for(start=0, cur=0; cur < Ctrl.value.length; cur++) {
  206.         for(i = 0; i < whitespace.length; i++) {
  207.             c = whitespace.charAt(i);
  208.             if (Ctrl.value.charAt(cur) == c) { // found whitespace
  209.                 if (space == false) { 
  210.                     space = true;  
  211.                     if(cur != start) { 
  212.                         host = Ctrl.value.substring(start,cur); 
  213. //                        if (flag == 1) host = host.indexOf(':',0);
  214.                         my_count++; 
  215.                         if (!testIPaddress(host,false)) { 
  216.                             errorBox (Ctrl, \"Invalid \" + what + \": \" + host); 
  217.                             return (false); 
  218.                         } 
  219.                     } 
  220.                 }
  221.                 break;
  222.             } else {                           // found character
  223.                 if (space == true) { 
  224.                     space = false;  
  225.                     start = cur; 
  226.                 }
  227.             }
  228.         }
  229.     }
  230.     if(cur != start && space == false) { 
  231.         host = Ctrl.value.substring(start,cur); 
  232. //        if (flag == 1) host = host.indexOf(':',0);
  233.         my_count++; 
  234.         if (!testIPaddress(host,false)) { 
  235.             errorBox (Ctrl, \"Invalid \" + what + \": \" + host
  236.                 + \"\\nin \" + what + \" list.\"); 
  237.             return (false); 
  238.         } 
  239.     }
  240.     return (true);
  241. }";
  242.  
  243.  
  244. #------------------------------------------------------------
  245. $js_ip = 
  246. "$js_check_int;
  247. function testIPaddress(address, netmask) {
  248.     start = 0;
  249.     while ((address.charAt(start) == ' ') || (address.charAt(start) == '\t')) {
  250.         start++;
  251.     }
  252.  
  253.     end = address.length - 1;
  254.     while ((end > 0) && ((address.charAt(end) == ' ') || (address.charAt(end) == '\t'))) {
  255.         end--;
  256.     }
  257.  
  258.     if ((start > 0) && (end == 0)) {
  259.         return (false);
  260.     }
  261.     
  262.     if (address.substring(start, start + 2) == \"0x\")  {
  263. if (! checkInt(address.substring(start + 2, end), 16)) return (false);
  264. //        if (isNaN(parseInt(address.substring(start + 2, end), 16))) {
  265. //            return (false);
  266. //        }
  267.         if (netmask) {
  268.             for (state = 0, start += 2; start <= end; start++) {
  269.                 value = address.charAt(start);
  270.                 if (value == 'f') {
  271.                     if (state != 0) {
  272.                         return (false);
  273.                     }
  274.                 } else if ((value == 'c') || (value == 'e')) {
  275.                     if (state != 0) {
  276.                         return (false);
  277.                     }
  278.                     state = 1;
  279.                 } else if (value == '0') {
  280.                     state = 1;
  281.                 } else {
  282.                     return (false);
  283.                 }
  284.             }
  285.         }
  286.         return (true);
  287.     }
  288.  
  289.     for (state = 0, count = 0; start <= end; count++) {
  290.         dot = address.indexOf('.', start);
  291.         if (dot < 0) {
  292.             dot = end + 1;
  293.         } else if (dot == 0 || dot == end) {
  294.             return (false);
  295.         }
  296. //        if (isNaN(parseInt(address.substring(start, dot), 10))) {
  297.         if (! checkInt(address.substring(start, dot), 10)) {
  298.             return (false);
  299.         }
  300.         value = parseInt(address.substring(start, dot), 10);
  301.         if (netmask) {
  302.             if (value == 255) {
  303.                 if (state != 0) {
  304.                     return (false);
  305.                 }
  306.             } else if ((value == 254) || (value == 252) ||
  307.                 (value == 248) || (value == 240) || (value == 224) ||
  308.                 (value == 192) || (value == 128)) {
  309.                 if (state != 0) {
  310.                     return (false);
  311.                 }
  312.                 state = 1;
  313.             } else if (value == 0) {
  314.                 state = 1;
  315.             } else {
  316.                 return (false);
  317.             }
  318.         }
  319.         if ((value > 255) || (value < 0)) {
  320.             return (false);
  321.         }
  322.         start = dot + 1;
  323.     }
  324.     if (count > 4) {
  325.         return (false);
  326.     }
  327.     return (true);
  328. }";
  329.  
  330.  
  331. #------------------------------------------------------------
  332. $js_hostlist =
  333. "function testHostlist(Ctrl, what) {
  334.     whitespace = \" \\n\\r\\t\\f\";  space = true;
  335.     for(start=0, cur=0; cur < Ctrl.value.length; cur++) {
  336.         for(i = 0; i < whitespace.length; i++) {
  337.             c = whitespace.charAt(i);
  338.             if (Ctrl.value.charAt(cur) == c) { // found whitespace
  339.                 if (space == false) { 
  340.                     space = true;  
  341.                     if(cur != start) { 
  342.                         host = Ctrl.value.substring(start,cur); 
  343.                         if (!testHostname(Ctrl, host, what, 0)) return (false); 
  344.                     } 
  345.                 } 
  346.                 break;
  347.             } else {                           // found character
  348.                 if (space == true) { 
  349.                     space = false;  
  350.                     start = cur; 
  351.                 }
  352.             }
  353.         }
  354.     }
  355.     if(cur != start && space == false) { 
  356.         host = Ctrl.value.substring(start,cur); 
  357.         if (!testHostname(Ctrl, host, what, 0)) return (false); 
  358.     }
  359.     return (true);
  360. }";
  361.  
  362.  
  363. #------------------------------------------------------------
  364. $js_hostname =
  365. "$js_check_int;
  366. function testHostname(Ctrl, host, what, flag) {
  367.     if (host == \"\") { 
  368.         if (flag == 1) return (true);
  369.         errorBox (Ctrl, \"The \" + what + \" is required.\"); 
  370.         return (false); 
  371.     }
  372.     error = testHost(host);
  373.     if (error == 1) { 
  374.         errorBox (Ctrl, \"The \" + what + \" cannot \\ncontain \" 
  375.             + illegal + \" characters.\"); 
  376.         return (false); 
  377.     }
  378.     if (error == 2) { 
  379.         errorBox (Ctrl, \"The \" + what + \" cannot start or \\n \"
  380.             + \"end with a . or - or _ character.\"); 
  381.         return (false); 
  382.     }
  383.     if (error == 3) { 
  384.         errorBox (Ctrl, \"The \" + what + \" cannot contain \\n\"
  385.             + \"consecutive . or - or _ characters.\"); 
  386.         return (false); 
  387.     }
  388.     if (error == 4) { 
  389.         errorBox (Ctrl, \"The \" + what + \" cannot contain spaces.\"); 
  390.         return (false); 
  391.     }
  392.     if (error == 5) { 
  393.         errorBox (Ctrl, \"The \" + what + \" cannot begin \\nwith \"
  394.             + \"a number.\"); 
  395.         return (false); 
  396.     }
  397.     return (true);
  398. }
  399. function testHost(word) {
  400.     metaChars = \"{}()*!~<>?|[]'&^\$\@\#`\\\";:\\\\/+=,%\";
  401.     start = 0;  
  402.     while (word.charAt(start) == ' ') { start++; }
  403.     end = word.length-1; 
  404.     while (word.charAt(end) == ' ') { end--; }
  405.     for(j = 0; j < metaChars.length; j++) {
  406.         c = metaChars.charAt(j); 
  407.         i = word.indexOf(c, 0); 
  408.         if (i != -1) { illegal = c; return 1; }
  409.     }
  410.     sch = word.charAt(start); ech = word.charAt(end);
  411.     if(sch == '.' || sch == '-' || sch == '_') return 2;
  412.     if(ech == '.' || ech == '-' || ech == '_') return 2;
  413.     for(j = start; j <= end; j++) { 
  414.         ch = word.charAt(j); 
  415.         if (ch == '.' || ch == '-' || ch == '_') { 
  416.             if (word.charAt(j+1) == ch) return 3; 
  417.         } if (ch == ' ') { return 4; } 
  418.     }
  419.     if (checkInt(sch, 10)) return 5;
  420. //    if(!isNaN(parseInt(sch))) return 5;
  421.     return 0;
  422. }";
  423.  
  424.  
  425. #------------------------------------------------------------
  426. $js_filename =
  427. "function testFilename(Ctrl, what) {
  428.     word = Ctrl.value;
  429.     if (word == \"\") {
  430.         errorBox (Ctrl, \"The \" + what + \" is required.\");
  431.         return (false);
  432.     }
  433.     if (!testFileChars(word)) {
  434.         errorBox (Ctrl, \"The \" + what + \" cannot \\ncontain \"
  435.             + illegal + \" characters.\");
  436.         return (false);
  437.     }
  438.     for(i = 0; i < word.length; i++) {
  439.         if (word.charAt(i) == ' ') {
  440.             errorBox (Ctrl, \"The \" + what + \" cannot \\ncontain spaces.\");
  441.             return (false);
  442.         }
  443.     }
  444.     if (word.charAt(0) != '/') {
  445.         errorBox (Ctrl, \"The \" + what + \" must be fully qualified.\");
  446.         return (false);
  447.     }
  448.     return (true);
  449. }
  450. function testFileChars(word) {
  451.     metaChars = \"{}()*!~<>?|[]'&^\$\@\#`\\\";:\";
  452.     for(j = 0; j < metaChars.length; j++) {
  453.         illegal = metaChars.charAt(j);
  454.         if (word.indexOf (illegal, 0) != -1) return (false);
  455.     } return (true);
  456. }";
  457.